package day06;

import java.util.Arrays;
import java.util.Random;

public class MethodDemo {
    public static void main(String[] args) {
        say(); //调用say()方法
        //sayHello();  //编译错误有参必须传参
        //sayHello(250);  //编译错误参数类型必须匹配
        say("张三");  //方法的重载
        say("张三",25);  //方法的重载
        int a = sum(4,5);  //sum(5,6)的值就是return后的那个数
        System.out.println(a);  //11---模拟对返回值的后续操作
        int m=5,n=6;
        int b = sum(m,n);  //传的是m和n里面的数
        System.out.println(b);  //11---模拟对返回值的后续操作
        System.out.println("--------------------------");
        int[] c = generateArray(10,100);  //模拟第一个人访问
        System.out.println("数组的长度"+c.length);
        for (int i=0;i<c.length;i++){
            Random ran = new Random();
            c[i] = ran.nextInt(100);
            System.out.println(c[i]);
        }
        System.out.println("------------------");
        int[] d = generateArray(10,100);  //模拟第二个人访问
        System.out.println("输出数组第一个元素"+d[0]);
        Arrays.sort(d);
        for (int i=0;i<d.length;i++){
            System.out.println(d[i]);
        }
    }
    //无参无返回值
    public static void say(){
        System.out.println("大家好，我叫gxh，今年20岁了");
    }
    public static void say(String name){
        System.out.println("大家好，我叫："+name);
    }
    //有参无返回值
    public static void say(String name,int age){
        System.out.println("大家好，我叫"+name+"今年"+age+"岁了");
    }
    //public static int say(){return 1;}  //编译错误，重载与返回值类型无关
    //public static void say(String address){} //编译错误，重载与参数名称无关
    //有参有返回值
    public static int sum(int num1,int num2){
        int num = num1+num2;
        return num; //返回的是num里面的那个数
        //return num1+num2; //返回的是num1与num2的和
    }
    public static int[] generateArray(int len,int max){
        Random ran = new Random();
        int[] arr = new int[len];
        for (int i=0;i<arr.length;i++){
            arr[i] = ran.nextInt(max+1);
        }
        return arr;
    }


}
